Is there a good way to remove a character from a string without copying all the characters following

Posted by piemesons on Stack Overflow See other posts from Stack Overflow or by piemesons
Published on 2010-05-21T18:17:17Z Indexed on 2010/05/27 22:51 UTC
Read the original article Hit count: 144

Filed under:
|
|

I was given an interview question:

// The first example:
char text[] = "henri";
char *p;
p = text;
*(p + 1) = 'E'; // Output = hEnri
// Now If we want to remove the "e" ie hnri, we would go for?????
     *(p + 1)=????? 

The obvious answer is to copy the rest of the array "back" one position. But this seems... unpleasant. Surely there is some better way?

© Stack Overflow or respective owner

Related posts about c

    Related posts about arrays